/**
 * 竞争信息
 * Created by wenchuan.li on 2018/06/15 08:23.
 */
define(function () {

    var self,
        app = win.app,
        others = {
            GWBHACTI:'N',
            from:''
        },
        subOrders = [],
        pageParameters
    ;

    var Jzxx = app.Module.extend({

        init: function () {
            self = this;
            self._super({
                _limit: 20,
                _refreshAutoInit: true, //自动加载刷新控件
                _readyBefore: function () {
                    pageParameters = self._pageParameters;
                    others.GWBHACTI = pageParameters.GWBHACTI;
                    others.from = pageParameters._from;
                }
            }, win);
        },
        _initRefresh: function () { // 实例化刷新组件
            if (self._refreshIds.length == 0) {
                self._refreshIds = ['pullrefresh'];
            }
            this._super(win);
        },
        _refreshCb: function (goods) {// 刷新组件回调函授
            var _super = this._super;
            app.ajax({
                xurl: "api/wx/gwat161/getJzxx",
                // xtime: '1d',
                xdata: {
                    page:goods.page+1,
                    limit: goods.limit,
                    GWBJNAME:pageParameters.GWBHNAME,
                   // GWBJID:pageParameters.gwak001
                },
                cb: function (result) {
                    if (result.ok) {
                        var datas = result.data.data;

                        _super({
                            obj: goods,
                            data: datas,
                            nodata: '暂无竞争信息...'
                        });

                    }
                }
            });
        },
        _lazy: function () {
            this._super();
            new Vue({
                el: app.getByid(doc, 'opBg'),
                data: {
                    GWBHACTI:pageParameters.GWBHACTI
                },
                methods:{
                    showmsg:function () {
                        app.toast('该拜访记录已经审核，无法修改');
                        return;
                    }
                }
            });

            new Vue({
                el: app.getByid(doc, 'contentFooter'),
                data: others,
                methods: {
                    addJzxx: function () {
                        app.openPage({
                            src: "hn-bfjltb/jzxx-edit.html",
                            args: {
                                _targer: 'jzxx-add',
                                GWBJNAME:pageParameters.GWBHNAME,
                                GWBJID:pageParameters.GWAK001,
                                cb: function (order) {
                                    self._refresh();
                                }
                            }
                        });
                    },
                    toBack:function () {
                        app.back(1);
                    }
                }
            });
        },
        _ready: function () {
            Vue.component('jzxx-template', {
                template: app.getByid(doc, 'jzxx-template'),
                props: {
                    model: Array
                },
                methods: {
                    showDetail: function (val) {
                        app.openPage({
                            src: "hn-bfjltb/jzxx-edit.html",
                            args: {
                                _targer: 'read',
                                type: 'jzxx-update',
                                item: val,
                                cb: function () {
                                    self._refresh();
                                }
                            }
                        });
                    },
                    deleteDetail: function(val, elobj){
                        app.confirm({
                            msg: '是否删除？',
                            ok: function () {
                                // app.ajax({
                                //     xurl: "api/wx/gwat300/delete",
                                //     xdata: val,
                                //     cb: function (result) {
                                //         if (result.ok) {
                                //             self._getRefreshObj().data.remove(val);
                                //             mui.swipeoutClose(Zepto(elobj.target).parents("li").get(0));
                                //         }
                                //     }
                                // });
                            }
                        });
                    }
                }
            });
        }
    });

    return new Jzxx();

});